import { layer } from "@layui/layer-vue";

/**
 * 验证手机号
 * @param value 
 * @returns 
 */
export const checkMobile = value => {
    return /^1\d{10}$/.test(value);
}
/**
 * 验证邮箱
 * @param value 
 * @returns 
 */
export const checkEmail = value => {
    return /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test(value);
}
/**
 * 验证验证码
 * @param value 
 * @returns 
 */
export const checkActiveCode = value => {
    if (value.length != 4 || isNaN(Number(value))) {
        return false;
    }
    return true;
}
/**
 * 自定义数据验证
 * @param rules 
 * @returns 
 */
export const validator = rules => {
    return rules.every(item => {
        let result = item.validator(item.value)
        !result && layer.msg(item.message);
        return result;
    })
}